package com.wfh.sql.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wfh.sql.common.ErrorCode;
import com.wfh.sql.constant.UserConstant;
import com.wfh.sql.exception.BusinessException;
import com.wfh.sql.model.entity.User;
import com.wfh.sql.service.UserService;
import com.wfh.sql.mapper.UserMapper;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Service;

/**
* @author fenghuanwang
* @description 针对表【user(用户)】的数据库操作Service实现
* @createDate 2025-10-17 15:12:07
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService{

    /**
     * 获取当前登录用户
     *
     * @param request
     * @return
     */
    @Override
    public User getLoginUser(HttpServletRequest request) {
        Object attribute = request.getSession().getAttribute(UserConstant.USER_LOGIN_STATE);
        User user = (User) attribute;
        if (user == null) throw new BusinessException(ErrorCode.NOT_LOGIN_ERROR);
        return user;
    }
}




